﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;

namespace System.Management.HyperV.MsBuildTasks
{
    public class ApplySnapshot : Task
    {
        [Required]
        public string VirtualMachineName
        {
            get;
            set;
        }

        [Required]
        public string SnapshotName
        {
            get;
            set;
        }

        public override bool Execute()
        {
            try
            {
                using (var vsms = new VirtualSystemManagementService())
                {
                    vsms.ApplyVirtualSystemSnapshot(VirtualMachineName, SnapshotName);
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
